<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let selectSort = (nums) => {
      for (let i = 0; i < nums.length; i++) {
        let minIndex = i
        for (let j = i + 1; j < nums.length; j++) {
          if (nums[j] < nums[minIndex]) {
            minIndex = j
          }
        }
        let tem = nums[i];
        nums[i] = nums[minIndex];
        nums[minIndex] = tem
      }
      return nums
    }
    console.log(selectSort([15, 456, 87, 126, 9, 7, 1,]))
    /*
      冒泡法 每次比较和移动相邻的两项
      选择排序 每次交换当前项和第n项
      总的说，这两种排序比较的次数是相同的，但交互的次数，选择排序是更少的
     */
  </script>
</body>

</html>